package com.test.blogsystem.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.test.blogsystem.Mapper.BlogMapper;
import com.test.blogsystem.Pojo.DO.BlogInfo;
import com.test.blogsystem.Pojo.Response.BlogInfoResponse;
import com.test.blogsystem.Service.BlogService;
import com.test.blogsystem.Utils.MyBeanUtil;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class BlogServiceImpl implements BlogService {
    @Autowired
    private BlogMapper blogMapper;

    @Override
    public List<BlogInfoResponse> getList() {
        QueryWrapper<BlogInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BlogInfo::getDeleteFlag, 0);
        List<BlogInfo> blogInfos = blogMapper.selectList(queryWrapper);

        return blogInfos.stream().map(blogInfo -> MyBeanUtil.transBlogInfo(blogInfo))
                .collect(Collectors.toList());
    }

    @Override
    public BlogInfoResponse getBlogDetail(Integer blogId) {
        QueryWrapper<BlogInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BlogInfo::getUserId, blogId);
        BlogInfo blogInfo = blogMapper.selectOne(queryWrapper);

        return MyBeanUtil.transBlogInfo(blogInfo);
    }
}
